#include "visbasehashcontainer.h"
#include "visbasecontainer.h"

VisBaseHashContainer::VisBaseHashContainer(QPointer<SageVis> sageVisPointer, QPointer<VisBaseWidget> parentWidget, QGraphicsItem *parent ) :
    VisBaseContainer( sageVisPointer, parentWidget, parent )
{

}


void VisBaseHashContainer::addElement(QPointer< VisBaseElement > e, QString hashKey)
{
    hashTable.insert(hashKey, e);
    super::addElement(e);
}


void VisBaseHashContainer::addElement(QPointer< VisBaseElement > e)
{
    super::addElement(e);
}

void VisBaseHashContainer::hashElement(QPointer< VisBaseElement > e, QString hashKey)
{
    hashTable.insert(hashKey, e);
}

QList< QPointer<VisBaseElement> > VisBaseHashContainer::getElements(QString hashKey)
{
    return hashTable.values( hashKey );
}

void VisBaseHashContainer::connectElementsWithSameKey(int type)
{
    QList<QString> keys = hashTable.uniqueKeys();//get all the keys
    qDebug() << keys.size();
    qDebug() << elements.size();

    float aveEltsPerKey = 0.0;

    for(int i = 0; i < keys.size(); i++)//for all unique keys
    {
        QList< QPointer< VisBaseElement > > elts = hashTable.values( keys[i] );//get list of elements with that key
        aveEltsPerKey += elts.size();
        for(int j = 0; j < elts.size(); j++) //for all the elements with this key
        {
            for(int k = j+1; k < elts.size(); k++) //loop through all other elements with this key
            {
                forgeConnection( elts[j], elts[k], type ); //connect these elements together
                //elts[j]->forgeConnection( elts[k], HOVER_CONNECTION );
                //elts[k]->forgeConnection(elts[j], HOVER_CONNECTION );
            }
        }
    }

    aveEltsPerKey /= (float)keys.size();

    qDebug() << "done " << aveEltsPerKey << endl;
}
